package com.dylon.baseStudy;

public class TryCatchTest {

    public static void main(String[] args) {
        System.out.println(test1());
        System.out.println("----------------");
        System.out.println(test2());
        System.out.println("----------------");
        System.out.println(test3());
        System.out.println("----------------");
        System.out.println(test4());

    }

    public static String test1(){
        try {
            // 1
            System.out.println("try execute!");
            // 2
            return "over";
        } catch (Exception e){
            // 3
            System.out.println("error catch "+e.getMessage());
        } finally {
            // 4
            System.out.println("finally execute");
        }
        // 5
        return "all over";

        // 顺序 1 > 4 > 2  结束
    }

    public static String test2(){
        try {
            // 1
            System.out.println("try execute!");
            // 2
            return "over";
        } catch (Exception e){
            // 3
            System.out.println("error catch "+e.getMessage());
        } finally {
            // 4
            System.out.println("finally execute");
            // 5
            return "all over";

            // 顺序 1 > 4 > 5  结束
        }
    }

    public static String test3(){
        try {
            // 1
            System.out.println("try execute!");
            // 2
            int i = 1/0;
            // 3
            return "over";
        } catch (Exception e){
            // 4
            System.out.println("error catch "+e.getMessage());
            // 5
            return "error over";
        } finally {
            // 6
            System.out.println("finally execute");
        }

        // 顺序 1 > 2 > 4 > 6 > 5  结束
    }

    public static String test4(){
        try {
            // 1
            System.out.println("try execute!");
            // 2
            int i = 1/0;
            // 3
            return "over";
        } catch (Exception e){
            // 4
            System.out.println("error catch "+e.getMessage());
            // 5
            return "error over";
        } finally {
            // 6
            System.out.println("finally execute");
            // 7
            return "all over";
        }

        // 顺序 1 > 2 > 4 > 6 > 7  结束
    }
}
